<!DOCTYPE html>
<html ng-app="demoApp">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>日期选择器 - ng-components-ui</title>
    <link rel="stylesheet" href="../dist/ng-components.css" />
    <style>
      * {
        box-sizing: border-box;
      }

      body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
        margin: 0;
        padding: 0;
        background: #f5f5f5;
      }

      .header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 30px 40px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      }

      .header h1 {
        margin: 0 0 10px 0;
        font-size: 32px;
      }

      .header p {
        margin: 0;
        opacity: 0.9;
        font-size: 16px;
      }

      .back-link {
        display: inline-block;
        margin-top: 15px;
        color: white;
        text-decoration: none;
        padding: 8px 16px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
        transition: background 0.2s;
      }

      .back-link:hover {
        background: rgba(255, 255, 255, 0.3);
      }

      .container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 40px;
      }

      .demo-section {
        background: white;
        padding: 30px;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        margin-bottom: 30px;
      }

      .demo-section h2 {
        margin: 0 0 20px 0;
        color: #333;
        font-size: 20px;
        border-bottom: 2px solid #667eea;
        padding-bottom: 10px;
      }

      .demo-section h3 {
        margin: 20px 0 15px 0;
        color: #555;
        font-size: 16px;
        font-weight: 600;
      }

      .demo-section p {
        color: #666;
        line-height: 1.6;
        margin: 0 0 15px 0;
      }

      .demo-row {
        margin: 20px 0;
        display: flex;
        align-items: center;
        gap: 20px;
      }

      .demo-row label {
        min-width: 120px;
        color: #555;
        font-weight: 500;
      }

      .demo-row ng-date-picker {
        flex: 1;
        max-width: 300px;
      }

      .code-block {
        background: #f7fafc;
        border: 1px solid #e2e8f0;
        border-radius: 4px;
        padding: 15px;
        margin: 10px 0;
        font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
        font-size: 12px;
        overflow-x: auto;
      }

      .code-block code {
        color: #2d3748;
      }

      .feature-list {
        background: #f7fafc;
        border-left: 4px solid #667eea;
        padding: 15px 20px;
        margin: 20px 0;
      }

      .feature-list ul {
        margin: 0;
        padding-left: 20px;
      }

      .feature-list li {
        color: #4a5568;
        margin: 8px 0;
        line-height: 1.6;
      }

      .selected-value {
        margin-top: 10px;
        padding: 10px;
        background: #e6f3ff;
        border-radius: 4px;
        color: #0066cc;
        font-size: 13px;
      }
    </style>
  </head>
  <body ng-controller="DemoController">
    <div class="header">
      <h1>日期选择器组件</h1>
      <p>轻量级日期选择器，支持日期范围限制和自定义格式</p>
      <a href="home.html" class="back-link">← 返回主页</a>
    </div>

    <div class="container">
      <div class="demo-section">
        <h2>日期选择器 (ng-date-picker)</h2>

        <div class="feature-list">
          <strong>功能特性:</strong>
          <ul>
            <li>支持字符串和 Date 对象两种数据格式</li>
            <li>可自定义日期格式（YYYY-MM-DD 等）</li>
            <li>支持最小/最大日期限制</li>
            <li>可配置周一或周日为每周第一天</li>
            <li>支持清空和禁用状态</li>
            <li>快捷选择今天按钮</li>
          </ul>
        </div>

        <h3>1. 基本用法</h3>
        <p>最基本的日期选择器</p>
        <div class="demo-row">
          <label>选择日期：</label>
          <ng-date-picker
            ng-model="date1"
            placeholder="请选择日期"
          ></ng-date-picker>
        </div>
        <div class="selected-value" ng-if="date1">
          选中日期：{{date1}}
        </div>

        <div class="code-block">
          <code>
&lt;ng-date-picker<br>
&nbsp;&nbsp;ng-model="date1"<br>
&nbsp;&nbsp;placeholder="请选择日期"&gt;<br>
&lt;/ng-date-picker&gt;
          </code>
        </div>

        <h3>2. 自定义格式</h3>
        <p>通过 <code>format</code> 属性设置日期格式</p>
        <div class="demo-row">
          <label>自定义格式：</label>
          <ng-date-picker
            ng-model="date2"
            format="YYYY年MM月DD日"
            placeholder="YYYY年MM月DD日"
          ></ng-date-picker>
        </div>
        <div class="selected-value" ng-if="date2">
          选中日期：{{date2}}
        </div>

        <div class="code-block">
          <code>
&lt;ng-date-picker<br>
&nbsp;&nbsp;ng-model="date2"<br>
&nbsp;&nbsp;format="YYYY年MM月DD日"&gt;<br>
&lt;/ng-date-picker&gt;
          </code>
        </div>

        <h3>3. 日期范围限制</h3>
        <p>通过 <code>min-date</code> 和 <code>max-date</code> 限制可选日期范围</p>
        <div class="demo-row">
          <label>限制范围：</label>
          <ng-date-picker
            ng-model="date3"
            min-date="minDate"
            max-date="maxDate"
            placeholder="仅能选择最近30天"
          ></ng-date-picker>
        </div>
        <div class="selected-value" ng-if="date3">
          选中日期：{{date3}}
        </div>

        <div class="code-block">
          <code>
// Controller<br>
var today = new Date();<br>
$scope.minDate = new Date(today.getTime() - 15 * 24 * 60 * 60 * 1000);<br>
$scope.maxDate = new Date(today.getTime() + 15 * 24 * 60 * 60 * 1000);<br>
<br>
// HTML<br>
&lt;ng-date-picker<br>
&nbsp;&nbsp;ng-model="date3"<br>
&nbsp;&nbsp;min-date="minDate"<br>
&nbsp;&nbsp;max-date="maxDate"&gt;<br>
&lt;/ng-date-picker&gt;
          </code>
        </div>

        <h3>4. 禁用状态</h3>
        <div class="demo-row">
          <label>禁用：</label>
          <ng-date-picker
            ng-model="date4"
            disabled="true"
            placeholder="已禁用"
          ></ng-date-picker>
        </div>

        <h3>5. 不可清空</h3>
        <div class="demo-row">
          <label>不可清空：</label>
          <ng-date-picker
            ng-model="date5"
            clearable="false"
            placeholder="不显示清空按钮"
          ></ng-date-picker>
        </div>

        <h3>6. 周一为第一天</h3>
        <p>通过 <code>start-week-on-monday="true"</code> 设置周一为每周第一天</p>
        <div class="demo-row">
          <label>周一开始：</label>
          <ng-date-picker
            ng-model="date6"
            start-week-on-monday="true"
            placeholder="周一为第一天"
          ></ng-date-picker>
        </div>

        <h3>7. Date 对象格式</h3>
        <p>ngModel 可以绑定 Date 对象</p>
        <div class="demo-row">
          <label>Date 对象：</label>
          <ng-date-picker
            ng-model="dateObject"
            placeholder="绑定 Date 对象"
          ></ng-date-picker>
        </div>
        <div class="selected-value" ng-if="dateObject">
          Date 对象：{{dateObject}}
        </div>
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/angular@1.8.3/angular.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/angular-strap@2.3.12/dist/angular-strap.min.js"></script>
    <script src="../dist/ng-components.js"></script>
    <script>
      angular
        .module("demoApp", ["ngComponents"])
        .controller("DemoController", function ($scope) {
          // 初始值
          $scope.date1 = "";
          $scope.date2 = "";
          $scope.date3 = "";
          $scope.date4 = "2024-01-01";
          $scope.date5 = "";
          $scope.date6 = "";
          $scope.dateObject = new Date();

          // 日期范围限制（前后15天）
          var today = new Date();
          $scope.minDate = new Date(today.getTime() - 15 * 24 * 60 * 60 * 1000);
          $scope.maxDate = new Date(today.getTime() + 15 * 24 * 60 * 60 * 1000);
        });
    </script>
  </body>
</html>
